# Section: Screen where install related stuff is

#:import launcher_config launcher_config
#:import get_color_from_hex kivy.utils.get_color_from_hex

<HoverButton>
    border: 1,1,1,1
    size_hint: None, None
    size: 256, 32
    text_size: None, self.height
    padding_x: 20

    # valign: 'middle'
    # Don't ask my why! "valign: 'middle'" aligns too high!
    # Workaround:
    padding_y: (self.height - self.font_size) / 2 - self.height / 12

    color: self.color_normal
    background_color: self.bgcolor_normal

    background_normal: ''
    background_down: ''
    background_disabled_normal: ''
    background_disabled_down: ''

    color_hover: [1, 1, 1, 1]
    color_normal: get_color_from_hex('#bfbfbf')
    disabled_color: get_color_from_hex('#302f3680')

    bgcolor_normal: 0, 0, 0, 0.5
    bgcolor_hover: get_color_from_hex('#212126')

    font_name: app.resource_path("fonts/Nexa_Light.ttf")
    font_size: 22
    on_release: app.play_sound('click')

<HoverButtonLeft@HoverButton>:
    text_size: self.size

<NewsLabel@RstDocument>
    size_hint: (None, None)
    colors: {'background': '00000080', 'link': 'ce5c00ff', 'paragraph': 'eeeeeeff', 'title': 'ffffccff', 'bullet': 'ffffffff'}
    underline_color: 'ffffccff'
    base_font_size: 24

<InstallScreen>:

    padding: 20
    name: 'install_screen'

    NewsLabel:
        id: news_label
        x: 0
        #top: root.top - 74
        #height: 380
        height: root.top - 74 - self.y
        y: main_buttons.top + 10
        width: 0
        width_final: 256
        direction: 'right'

        bar_width: 10
        scroll_type: ['bars', 'content']
        bar_inactive_color: 0.7, 0.7, 0.7, 0.4

#= Top =========================================================================

    Image:
        source: app.resource_path('images/logo.png')
        pos: root.width / 2 - self.width / 2, root.top - self.height - 7
        size_hint: None, None
        size: self.texture_size

    # Note: This button is hidden but can be brought and *should* work just fine :)
    HoverButton:
        id: selected_server
        font_size: 14
        font_name: app.resource_path("fonts/Nexa_Light.ttf")
        size: self.texture_size
        text_size: None, 32
        x: root.width / 2 - self.width / 2
        #top: root.top - 64 + 16 + self.height
        top: root.top + 5000
        on_release: root.controller.on_selected_server_button_release(self)
        text_prefix: '[font=fonts/Equality]=[/font]'
        markup: True
        text: 'SERVER SELECTION'
        disabled: True

        color_normal: [0, 0, 0, 1]
        color_hover: [0, 0, 0, 1]
        bgcolor_normal: get_color_from_hex('#eca92d')
        bgcolor_hover: get_color_from_hex('#ffc94d')

#= Menu ========================================================================

    ProgressBar:
        id: progress_bar
        value: 0
        height: 18
        y: status_box.height
        size_hint_y: None

    # Main status label ("Downloading... x KB/S")
    Label:
        id: status_label
        x: progress_bar.x + 40
        y: progress_bar.y - 2
        size: self.texture_size
        size_hint: None, None
        text_size: progress_bar.size
        #outline_width: 2
        color: 1, 1, 1, 1
        valign: 'middle'
        font_size: 14
        font_name: app.resource_path("fonts/Nexa_Bold.ttf")

    # Status box with the messages
    LabelB:
        #text: 'Frontline / CUP Core / CUP Terrains / RHS AFRF / RHS USAF / RHS GREF'
        id: status_box
        y: 0
        height: 64
        width: 744
        size_hint: None, None
        padding: 40, 10
        halign: 'left'
        valign: 'top'
        text_size: self.size
        color: get_color_from_hex('#bfbfbf')
        bcolor: get_color_from_hex('#212126')
        font_name: app.resource_path("fonts/Nexa_Light.ttf")
        font_size: 13

    StatusImage:
        id: status_image
        source_map: { 'default': app.resource_path('images/loader.zip'), 'attention': app.resource_path('images/achtung40x38.png') }
        anim_delay: 0.5
        pos: progress_bar.pos
        size: progress_bar.height, progress_bar.height
        size_hint: None, None
        hidden: True

#= Buttons =====================================================================

    # Vertical buttons
#     StackLayout:
#         id: main_buttons
#         y: status_box.top
#         x: 0
#         width: 256
#         size_hint_x: None
#         #size_hint_y: 0
#         orientation: 'bt-lr'
#         spacing: 4
#         padding: 0, 4 + progress_bar.height

    GridLayout:
        id: main_buttons
        cols: 1
        size_hint: None, None

        x: 0
        y: progress_bar.top + 10
        width: 256
        height: self.minimum_height

        spacing: 4

        # MakeTorrentButton
        HoverButtonLeft:
            disabled: True
            background_color: 0, 0, 0, 0
            size_hint_x: 1
            id: make_torrent
            on_release: root.controller.on_make_torrent_button_release(self)

        # DonateButton
        HoverButtonLeft:
            size_hint_x: 1
            text: 'DONATE'
            on_release: app.open_hyperlink(launcher_config.donate_url)

        # ForumButton
        HoverButtonLeft:
            text: 'FORUM'
            size_hint_x: 1
            on_release: app.open_hyperlink(launcher_config.forum_url)

        # ForumButton
        HoverButtonLeft:
            text: 'DISCORD'
            size_hint_x: 1
            on_release: app.open_hyperlink(launcher_config.discord_url)

        # OptionsButton
        HoverButtonLeft:
            id: options_button
            size_hint_x: 1
            on_release: app.root.ids.main_screen_manager.current = 'pref_screen'
            text: 'OPTIONS'
            disabled: False

    # Install/Play button
    DynamicButton:
        text_size: self.size
        id: action_button
        pos: status_box.right, 0
        # on_release callbacks are bound in installscreen.py
        #text: 'INSTALL'
        font_name: app.resource_path("fonts/Nexa_Bold.ttf")
        font_size: 32

        color_normal: [0, 0, 0, 1]
        color_hover: [0, 0, 0, 1]
        bgcolor_normal: get_color_from_hex('#eca92d')
        bgcolor_hover: get_color_from_hex('#ffc94d')
        size: 256, 64

    ServerListScrolled:
        id: server_list_scrolled
        x: status_box.right
        y: progress_bar.top + 10
        width: root.width - self.x
        max_height: root.top - 64 - 10 - self.y
        selection_callback: root.controller.set_selected_server

#= Other =======================================================================

    # Version number
    Label:
        id: footer_label
        text: 'Build: N/A'
        font_name: app.resource_path("fonts/Nexa_Light.ttf")
        font_size: 12
        #outline_width: 1

        size: self.texture_size
        color: get_color_from_hex('#606060')
        padding: [20, 20]
        size_hint: None, None
        pos_hint: {'right': 1, 'top': 1}
